package com.xbongbong.paas.help.factory;

import com.xbongbong.paas.help.factory.impl.OperatorDefaultHandlerImpl;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Map;
import java.util.Objects;

/**
 * 业务规则操作方式中字段工厂
 * @author 吴峰
 * @version v1.0
 * @date 2020/3/3 19:38
 * @since v1.0
 */
@Component
public class OperatorFieldHandlerFactory {

    @Resource
    @Lazy
    private Map<Integer, OperatorFieldHandler> operatorFieldHandlerMap;
    @Resource
    private OperatorDefaultHandlerImpl operatorDefaultHandler;
    /**
     * 业务规则操作方式本表单字段处理声明
     * @param fieldType
     * @return
     */
    public OperatorFieldHandler getHandlerByFieldType(Integer fieldType) {
//        FieldTypeEnum fieldTypeEnum = FieldTypeEnum.getFieldTypeEnum(fieldType);
//        switch (fieldTypeEnum) {
//            case COMBO:
//            case RADIO_GROUP:
//                return new OperatorComboHandlerImpl();
//            case COMBO_CHECK:
//            case CHECKBOX_GROUP:
//                return new OperatorComboCheckHandlerImpl();
//            case DATAID:
//                return new OperatorDataIdHandlerImpl();
//            case SERIALNO:
//                return new OperatorSerialNoHandlerImpl();
//            case STAGE_THRUSTER:
//                return new OperatorStageHandlerImpl();
//            default:
//                return new OperatorDefaultHandlerImpl();
//        }
        OperatorFieldHandler operatorFieldHandler = operatorFieldHandlerMap.get(fieldType);
        if (Objects.isNull(operatorFieldHandler)) {
            return operatorDefaultHandler;
        }
        return operatorFieldHandler;
    }
    /**
     * 业务规则操作方式目标表单字段处理声明
     * @param fieldType
     * @return
     */
    public OperatorFieldHandler getHandlerTargetFormByFieldType(Integer fieldType) {
//        FieldTypeEnum fieldTypeEnum = FieldTypeEnum.getFieldTypeEnum(fieldType);
//        switch (fieldTypeEnum) {
//            case COMBO:
//            case RADIO_GROUP:
//                return new OperatorComboHandlerImpl();
//            case COMBO_CHECK:
//            case CHECKBOX_GROUP:
//                return new OperatorComboCheckHandlerImpl();
//            case ADDRESS:
//                return new OperatorAddressHandlerImpl();
//            case IMAGE:
//                return new OperatorImageHandlerImpl();
//            case UPLOAD:
//                return new OperatorFileHandlerImpl();
//            case USER:
//                return new OperatorUserHandlerImpl();
//            case USER_GROUP:
//                return new OperatorUserGroupHandlerImpl();
//            case DATAID:
//                return new OperatorDataIdHandlerImpl();
//            case SERIALNO:
//                return new OperatorSerialNoHandlerImpl();
//            case DATETIME:
//                return new OperatorDateTimeHandlerImpl();
//            default:
//                return new OperatorDefaultHandlerImpl();
        OperatorFieldHandler operatorFieldHandler = operatorFieldHandlerMap.get(fieldType);
        if (Objects.isNull(operatorFieldHandler)) {
            return operatorDefaultHandler;
        }
        return operatorFieldHandler;
    }
    /**
     * 业务规则操作方式固定值处理声明
     * @param fieldType
     * @return
     */
    public OperatorFieldHandler getHandlerFixedValueByFieldType(Integer fieldType) {
//        FieldTypeEnum fieldTypeEnum = FieldTypeEnum.getFieldTypeEnum(fieldType);
//        switch (fieldTypeEnum) {
//            case COMBO:
//            case RADIO_GROUP:
//                return new OperatorComboHandlerImpl();
//            case COMBO_CHECK:
//            case CHECKBOX_GROUP:
//                return new OperatorComboCheckHandlerImpl();
//            case NUM:
//                return new OperatorNumHandlerImpl();
//            case ADDRESS:
//                return new OperatorAddressHandlerImpl();
//            case IMAGE:
//                return new OperatorImageHandlerImpl();
//            case USER:
//            case DEPT:
//                return new OperatorUserHandlerImpl();
//            case USER_GROUP:
//            case DEPT_GROUP:
//                return new OperatorUserGroupHandlerImpl();
//            case DATETIME:
//                return new OperatorDateTimeHandlerImpl();
//            default:
//                return new OperatorDefaultHandlerImpl();
//        }
        OperatorFieldHandler operatorFieldHandler = operatorFieldHandlerMap.get(fieldType);
        if (Objects.isNull(operatorFieldHandler)) {
            return operatorDefaultHandler;
        }
        return operatorFieldHandler;
    }
}
